<template>
	<view class="create_customer">
		<!-- 基础信息 -->
		<view class="info_head">基础信息</view>
		<form-item v-for="(item,index) in listForm" @changeData="changeData" :key="index" :objInfo="item" ></form-item>
		<!-- 其他信息 
		-->
		<view class="info_head">跟进任务</view>
		<view class="fllow_form">
			<view>创建下次跟进任务</view>
			<view class="fllow_button" style="margin-top: 10rpx;">
				<u-switch v-model="checked" size="40" @change="changeIs" active-color="#03AA96"/>
			</view>
		</view>
		<view v-if="is_event">
			<view class="fllow_form">
				<view>跟进时间</view>
				<picker @change="changeFollowTime" mode="date">
					<view class="form_right" >
						<view :class="start_time ? 'valueActive' : '' ">{{start_time ? start_time : '点击选择'}}</view>
						<view class="iconfont icon-arrows_right"></view>
					</view>
				</picker>
			</view>
			<view class="fllow_form">
				<view>跟进内容</view>
				<view class="form_right">
					<input placeholder-style="color:#999;font-size:32rpx;" type="text" :class="title ? 'valueActive' : '' " v-model="title" placeholder="点击填写" />
				</view>
			</view>
			<view class="fllow_form">
				<view>任务提醒</view>
				<picker @change="changeRemind" :value="remindIndex" :range="remindList">
					<view class="form_right">
						<view :class="remindtype ? 'valueActive' : '' ">{{remindtype ? remindtype : '点击选择'}}</view>
						<view class="iconfont icon-arrows_right"></view>
					</view>
				</picker>
			</view>
		</view>
		<view id="btn" class="btn_g bg-blue button-hover round" @click="$noMultipleClicks(subSave)">
			保存
		</view>
	</view>
</template>

<script>
	import formItem from '@/components/form/formitem.vue'
	import { netAddClues } from '@/api/clues.js'
	import { netSetForm } from '@/api/index.js'
	import { checkPhone } from '@/util/util.js'
	export default {
		components:{
			formItem
		},
		data() {
			return {
				is_event:false,   //是否创建下次跟进任务
				start_time:'',
				title:'',
				remindtype:'',    //任务提醒
				source_list:[],   //线索 来源列表
				sourceIndex:null,
				industry_list:[],   //行业列表
				industryIndex:null,
				remindList:['准时提醒','5分钟前','15分钟前','30分钟前','一个小时前','两个小时前','一天前','两天前','一周前'],   //提醒
				remindIndex:null,
				
				listForm:[],
				baseForm:[],
				otherForm:[],
				noClick:true,  //防止重复点击
				
				
				checked: false,
			}
		},
		onLoad(options) {
			//获取 表单设置
			this.getForm()
		},
		onShow() {
			
		},
		methods: {
			getForm(){
				let params = {type:'leads'}
				netSetForm(params).then(res=>{
					let list = res.data.data
					list.forEach(ele=>{
						ele.value = ''
					})
					this.listForm = res.data.data
				})
			},
			changeData(name,value,obj){
				let arr = this.listForm
				arr.forEach((ele,index)=>{
					if(ele.id == obj.id){
						ele.value = value
						this.$set(this.listForm,index,ele)
					}
				})
			},
			//是否创建 下次跟进任务
			changeIs() {
				console.log('------')
				this.is_event = !this.is_event
			},
			//创建下次跟进 任务 时间
			changeFollowTime(e) {
				this.start_time = e.detail.value
			},
			//任务提醒
			changeRemind(e) {
				this.remindIndex = e.detail.value
				this.remindtype = this.remindList[e.detail.value]
			},
			//完成
			subSave() {
				let leads = {}
				let arr = []
				this.listForm.forEach(ele=>{
					arr.push({
						name:ele.id,
						required: ele.config.required,
						msg: ele.config.placeholder,
						value:ele.value
					})
				})
				for(let i = 0; i < arr.length ; i++) {
					if(arr[i].required && !arr[i].value){
						uni.showToast({
							title: arr[i].msg,
							icon:'none'
						})
						return
					}
					if(arr[i].required && arr[i].name == 'mobile' && !checkPhone(arr[i].value)){
						uni.showToast({
							title: '请填写正确的手机号/电话',
							icon:'none'
						})
						return
					}
					if(arr[i].required && arr[i].name == 'telephone' && !checkPhone(arr[i].value)){
						uni.showToast({
							title: '请填写正确的手机号/电话',
							icon:'none'
						})
						return
					}
					if((arr[i].name == 'telephone' || arr[i].name == 'mobile') && arr[i].value && !checkPhone(arr[i].value)){
						uni.showToast({
							title: '请填写正确的手机号/电话',
							icon:'none'
						})
						return
					}
					leads[arr[i].name] = arr[i].value
				}
				let {
					is_event,   //是否创建下次跟进任务
					start_time,
					title,
					remindtype,
					remindIndex	//任务提醒
				} = this
				let event = {
					start_time, title, remindtype:remindIndex
				}
				let params = {
					is_event: is_event ? 1 : 0
				}
				params.event = event
				params.leads = leads
				console.log(params)
				netAddClues(params).then(res=>{
					uni.showToast({
						title:res.msg,
						icon:'none'
					})
					setTimeout(()=>{
						uni.navigateBack({
							delta:1
						})
					},2000)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.valueActive{
	color:#333;
}
.create_customer {
	font-size: 28rpx;
	.info_head {
		height: 80rpx;
		line-height: 80rpx;
		font-size: 32rpx;
		color: #999;
		padding-left: 55rpx;
	}
	.mar_top {
		margin-top: 30rpx;
	}
	.fllow_form {
		display: flex;
		justify-content: space-between;
		height: 100rpx;
		line-height: 100rpx;
		background-color: #fff;
		border-bottom: 1rpx solid #EAEAEA;
		padding: 0 24rpx;
		font-size: 32rpx;
		.form_right {
			display: flex;
			align-items: center;
			color: #999;
			text-align: right;
			image {
				width: 40rpx;
				height: 40rpx;
				margin: 35rpx 5rpx 0 0;
			}
		}
		.theme {
			color: #5ca9fe;
		}
		text {
			color: #f00;
			margin-left: 10rpx;
		}
		.form_input {
			input {
				text-align: right;
				margin-right: 10rpx;
			}
		}
	}
}
#btn {
		font-size: 26rpx;
		color: #fff;
		text-align: center;
		line-height: 88rpx;
		width: 500rpx;
		height: 88rpx;
		background: #03AA96;
		border-radius: 29rpx;
		margin: 30rpx auto;
	}
</style>
